//
//  HTPriceView.swift
//  weibo
//
//  Created by JonsonLiu on 2017/3/15.
//  Copyright © 2017年 JonsonLiu. All rights reserved.
//

import UIKit

class HTPriceView: UIView {
    
    
    var urls : [HTStatesPicture]? {
        didSet{
            
            
            
//            for i in subviews{
//                
//                i.isHidden = true
//            }
//            
            
            var index = 0
            for url in urls ?? []
            {
            
                let vi = subviews[index] as! UIImageView
                
                vi.ht_setImage(urlString: url.thumbnail_pic, placeholderImage: nil)
                
                vi.isHidden = false
                
                index += 1
            }
        }
    }

    @IBOutlet weak var priceView : NSLayoutConstraint!
    
    override func awakeFromNib() {
        setupUI()
    }
    
    func setupUI(){
    
        
        
        let  count = 3
        let  rect = CGRect(x: 0, y: statePrictureViewMargin, width: statePrictureItemWidth, height: statePrictureItemWidth)
        
        for i in 0..<count * count {
            
            let  v = UIImageView()
            
            v.contentMode = .scaleAspectFill
            v.clipsToBounds = true
            
            let row = CGFloat(i / count)
            let col = CGFloat(i % count)
            
            let xOffset = col * (statePrictureItemWidth + statePrictureinnerMargin)
            let yOffset = row * (statePrictureItemWidth + statePrictureinnerMargin)
            
            
            
            v.frame = rect.offsetBy(dx: xOffset, dy: yOffset)
            
            addSubview(v)
            
        }
    }
    

}
